//
//  AEPointsAcquireMainSingleView.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/17.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEPointsAcquireMainSingleView.h"
#import "AE_Solar-Swift.h"

@interface AEPointsAcquireMainSingleView ()

@property (nonatomic, strong) TYZCommonCellModel *model;

@property (nonatomic, strong) CALayer *bottomLine;

@property (nonatomic, strong) UIImageView *thumalImgView;

@property (nonatomic, strong) UIButton *btnStatus;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UILabel *cntLabel;

- (void)initWithThumalImgView;

- (void)initWithBtnStatus;

- (void)initWithTitleLabel;

- (void)initWithCntLabel;

@end

@implementation AEPointsAcquireMainSingleView

- (void)initWithSubView {
    self.backgroundColor = kWhiteColor;
    
    
    CGRect frame = CGRectMake(10, self.height - 1, self.width - 10 * 2, 1);
    _bottomLine = [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#DFDFDD"]];
}

- (void)setBottomLineHidden:(BOOL)bottomLineHidden {
    _bottomLineHidden = bottomLineHidden;
    _bottomLine.hidden = bottomLineHidden;
}

- (void)initWithThumalImgView {
    if (!_thumalImgView) {
        CGRect frame = CGRectMake(10, (self.height - 39) * 0.5, 39, 39);
        _thumalImgView = [UIImageView createWithImageView:self frame:frame defaultImage:nil propertiesBlock:^(UIImageView * _Nonnull imageView) {
            
        }];
    }
    if (self.model) {
        self.thumalImgView.image = [UIImage imageNamed:self.model.iconImgName];
    }
}

- (void)initWithBtnStatus {
    if (!_btnStatus) {
        NSString *norTitle = [AEStringExten localizedValueWithKey:@"去完成"];
        NSString *selTitle = [AEStringExten localizedValueWithKey:@"已完成"];
        UIFont *font = [UIFont systemFontOfSize:10.5 weight:UIFontWeightMedium];
        float width = [norTitle widthForFont:font] + 2 + 20;
        CGRect frame = CGRectMake(self.width - 10 - width, (self.height - 24) * 0.5, width, 24);
        _btnStatus = [UIButton createWithButton:self frame:frame font:font target:self action:@selector(actionWithFinish:) propertiesBlock:^(UIButton * _Nonnull button) {
            [button setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#F65602"]] forState:UIControlStateNormal];
            [button setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"#DFDFDD"]] forState:UIControlStateSelected];
            [button setTitle:norTitle forState:UIControlStateNormal];
            [button setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
            [button setTitle:selTitle forState:UIControlStateSelected];
            [button setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateSelected];
            button.layer.cornerRadius = frame.size.height * 0.5;
            button.layer.masksToBounds = YES;
        }];
    }
    if (self.model) {
        self.btnStatus.selected = self.model.isCheck;
    }
}

- (void)initWithTitleLabel {
    UIFont *font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    if (!_titleLabel) {
        CGRect frame = CGRectMake(self.thumalImgView.right + 9.5, self.thumalImgView.top, self.btnStatus.left - self.thumalImgView.right - 9.5 - 8, 21);
        _titleLabel = [UILabel createWithLabel:self frame:frame font:font propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#333333"];
        }];
    }
    if (self.model) {
        self.titleLabel.text = self.model.title;
    }
}

- (void)initWithCntLabel {
    if (!_cntLabel) {
        CGRect frame = self.titleLabel.frame;
        frame.size.height = 14.5;
        frame.origin.y = self.thumalImgView.bottom - frame.size.height - 3;
        _cntLabel = [UILabel createWithLabel:self frame:frame font:[UIFont systemFontOfSize:10.5 weight:UIFontWeightMedium] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#FCBF62"];
        }];
    }
    if (self.model) {
        NSString *cnt = [AEStringExten localizedValueWithKey:@"积分"];
        NSString *title = [NSString stringWithFormat:@"%@+%@", cnt, self.model.value];
        self.cntLabel.text = title;
    }
}

- (void)actionWithFinish:(id)sender {
    UIButton *btn = (UIButton *)sender;
    if (btn.selected == NO) {
        if (self.touchGoFinishBlock) {
            self.touchGoFinishBlock();
        }
    }
}

- (void)updateWithViewData:(id)data {
    
    self.model = data;
    
    [self initWithThumalImgView];

    [self initWithBtnStatus];

    [self initWithTitleLabel];

    [self initWithCntLabel];

}


@end
